home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / Graphics / QuickDraw GX / GX->PostScript Sample / GXToPostScript / PostScriptFiles / FontModProcs.ps < prev    next >
Encoding:
Text File  |  2000-09-28  |  6.2 KB  |  238 lines  |  [TEXT/LTLK]

  1. %
  2. %    File:        FontProcs.ps
  3. %
  4. %    Contains:    This file contains Procedures the Used to do simple modifications of fonts.
  5. %
  6. %    Version:    Technology:    Quickdraw GX 1.1.x.
  7. %
  8. %    Copyright:    © 1991-7 by Apple Computer, Inc., all rights reserved.
  9. %
  10. %
  11.  
  12. %        File contains the following Procedures:
  13. %            MakeFontClone
  14. %            MakeFramedFont
  15. %            MakeBoldFont
  16. %            MakeVerticalFont
  17.  
  18. %<FF>
  19. %
  20. %    Procedure: MakeFontClone
  21. %
  22. %        Clones a font dictionary so we can change or add entries to it.
  23. %
  24. %        baseFontDict N MakeFontClone cloneFontDict
  25. %
  26. %        baseFontDict:            A valid font dictionary
  27. %        N:                                Number of dictionary entries to add.
  28. %
  29. /MakeFontClone {
  30.  
  31.     exch
  32.     dup length 3 -1 roll add dict begin             % Make dictionary big enough for new entries.
  33.     
  34.     % Duplicate all entries bug /FID and /UniqueID
  35.     {
  36.         1 index /FID ne 2 index /UniqueID ne and {def} {pop pop} ifelse
  37.     } forall
  38.  
  39.     currentdict
  40.     
  41.     end
  42.     
  43. } Bdef
  44.  
  45. %<FF>
  46. % Procedure:    MakeFramedFont
  47. %        Makes a frame-filled font from a base font
  48. %        This is accomplished by changing the PaintType to 2
  49. %        Of course, this would only work on fonts that obey this.
  50. %        But we know that all fonts do, right?
  51. %
  52. %        baseFontDict strokeWidth MakeFramedFont framedFontDict
  53. %
  54. %        baseFontDict:            A valid font dictionary
  55. %        strokeWidth:            Width of outline in user space for a 1 point character.
  56. %        outlineFontDict:    The new font dictionary, ready for definefont.
  57. %
  58. /MakeFramedFont {
  59.  
  60.     1 index /FontType get 0 ne {                % Terminal condition for recursive traversal of composite fonts.
  61.     
  62.         exch 2 MakeFontClone
  63.         begin 
  64.             /PaintType 2 def                                 % Change PaintType to 2.
  65.             0 FontMatrix idtransform pop        % Run strokeWidth through Font's matrix. 
  66.             /StrokeWidth Xdef
  67.         currentdict
  68.         end
  69.                 
  70.     } {                                                                % Traverse composite font recursively and make stroked base fonts.
  71.         
  72.         exch                                                                % Stack is: strokeWidth baseFontDict
  73.         0 MakeFontClone begin                                % Clone the composite font
  74.  
  75.             FDepVector length array                        % Make an array for the new FDepVector, leave on stack.
  76.             0                                                                    %    Index for array insertion
  77.             
  78.             FDepVector {                                            % Stack is: strokeWidth newArray index oldFDepEntry
  79.                 
  80.                 3 index                                                    % Stack is:        strokeWidth newArray index oldFDepEntry strokeWidth
  81.                 MakeFramedFont /FDepFramedFont
  82.                 exch definefont                                    % Stack is:        strokeWidth newArray index newFDepEntry
  83.                 3 copy put pop                                    % Stack is:        strokeWidth newArray index,  framed font in newArray.
  84.                 1 add                                                        %    Stack is:        strokeWidth newArray index+1
  85.                 
  86.             } forall
  87.             
  88.             pop                                                        % Stack is: strokeWidth newArray
  89.             /FDepVector Xdef                            %    Put new FDepVector in type-0 dictionary.
  90.             pop                                                        % Pop off copy of strokeWidth
  91.                     
  92.             currentdict                                        % Leave the current dictionary on stack.
  93.             
  94.         end
  95.     
  96.     } ifelse
  97.  
  98. } Bdef
  99.  
  100.  
  101. %<FF>
  102. %    Procedure: MakeVerticalFont
  103. %        Procedures changes the WMode entry of a font for vertical text
  104. %
  105. %        baseFontDict MakeVerticalFont verticalFontDict
  106. %
  107. /MakeVerticalFont {
  108.  
  109.     dup /WMode known {0} {1} ifelse MakeFontClone
  110.  
  111.     dup begin
  112.     
  113.         /WMode 1 def
  114.         
  115.     end
  116.  
  117. } Bdef
  118.  
  119.  
  120.  
  121.  
  122. %<FF>
  123. %
  124. %        BuildChar procedure for the bold font.
  125. %
  126. %            dict char BoldBuildChar
  127. %
  128. %        dict:        the bold font's font dictionary.
  129. %        char:        The character code from the base font to render.
  130. %
  131. %        The Bold procedure draws a bold glyph as follows:
  132. %            Stroke the path of the normal glyph with a non-square pen
  133. %            Draw the  normal glyph
  134. %            This routine is to be called from a type-3 font with the character code on the stack
  135. %                And the font dictionary at the top of the dictionary stack.
  136. %
  137. %
  138. /BoldBuildChar {
  139.     
  140.     exch begin
  141.  
  142.         theChar 0 3 -1 roll put                            % Put the character code into the string.
  143.  
  144.         baseFontDict setfont
  145.  
  146.         % Compute the new advance metric:  Old advance + boldness
  147.  
  148.         theChar stringwidth                                    % Get the advance widths of the normal character.
  149.         dup 0 ne {yBold add} if                            % If the y advance wasn't zero, add the y bold.
  150.         exch
  151.         dup 0 ne {xBold add} if                            % IF the x advance wasn't zero, add the x bold.
  152.         exch
  153.  
  154.  
  155.         % First compute the bounding box of the bold glyph
  156.  
  157.         gsave
  158.  
  159.         newpath
  160.         0 0 moveto
  161.         theChar false GXCharPath                % Get the path of the character
  162.  
  163.         gsave
  164.         % Get the bounding box of the non-square pen stroke
  165.         xBold 2 mul yBold 2 mul scale 1 setlinewidth strokepath
  166.         pathbbox
  167.  
  168.         grestore
  169.  
  170.         grestore
  171.         setcachedevice
  172.  
  173.  
  174.         % Now draw the bold glyph.
  175.         
  176.         newpath
  177.         0 0 moveto theChar true GXCharPath
  178.         %
  179.         %    Stroke the path with a non-square pen using sneaky scaling method.
  180.         %
  181.         currentlinewidth                                                                    % Save the current line width
  182.         xBold 2 mul                                                                                % Do scaling to get non-square pen.
  183.         yBold 2 mul
  184.         scale
  185.         1 setlinewidth                                                                        % set line width to 1, so when run through
  186.                                                                                                             %        The scale, it becomes xBold, yBold.
  187.         CharPathCount 0 eq {stroke} {strokepath} ifelse
  188.         
  189.         1 xBold 2 mul div 1 yBold 2 mul div scale                    % undo the scaling
  190.         setlinewidth                                                                            % restore the current line width
  191.         
  192.         0 0 moveto
  193.         theChar CharPathCount 0 eq {show} {true charpath} ifelse
  194.  
  195.     end
  196.  
  197. } Bdef
  198.  
  199.  
  200. %<FF>
  201. %
  202. %        Procedure to make a bold font from a base font.  However, these fonts cannot be used
  203. %            in any context that requires the proper functioning of the charpath operator.  Since
  204. %            this font calls charpath and charpath is not re-entrant, it is not possible to call
  205. %            charpath on this font.  Adobe really screwed up this time.
  206. %
  207. %        dict x y MakeBoldFont dict
  208. %
  209. %        dict:        the base font dictionary,.
  210. %        x y:        the x and y boldness values.  (Amount to outset the glyphs)
  211. %        dict:        The new font dictionary for the bold font.
  212. %
  213. /MakeBoldFont {
  214.  
  215.         20 dict dup begin                        % Create the new font dictionary, leave it on stack and dict stack.
  216.             4 1 roll                                    % Put duplicate of dict ref behind parameters on stack.
  217.  
  218.             /yBold Xdef                                % Save the boldness values.
  219.             /xBold Xdef
  220.  
  221.             /baseFontDict Xdef                % Save the base font dictionary reference.
  222.  
  223.             /theChar 1 string def            % Place for characters.
  224.  
  225.             baseFontDict /Encoding get /Encoding Xdef                % Copy the base font's encoding.
  226.             /FontType 3 def                                                                    % New font will be type 3
  227.             /FontMatrix [1 0 0 1 0 0] def                                        % Don't muck with base font's coordinates.
  228.             /FontBBox [0 0 0 0] def                                                    % This is safest.
  229.  
  230.             %
  231.             % Now define the buildChar procedure.
  232.             %
  233.             /BuildChar /BoldBuildChar load def
  234.  
  235.         end
  236.  
  237. } Bdef
  238.